Pinned Images#1519
Conversation
| response={200: None, 400: dict, 403: dict}, | ||
| include_in_schema=False, | ||
| ) | ||
| def image_set_pinned(request, id: int, payload: SetPinned): |
There was a problem hiding this comment.
Should this just be a form endpoint instead? That's a real question, not a suggestion.
@danlamanna Thoughts?
|
@brianhelba Thanks for the suggestions. I can definitely make these changes, but I'll first ask if we should make the same changes in the following places:
I had copied code from each of these places so I could mimic the pinning behavior of collections. Should we try to keep them the same? |
|
Good point. Since this is already getting to be a larger PR, I'd say is actually fine to keep here as-is, then make a follow-up PR to improve all these places. |
26b76b1 to
550dd78
Compare
7568855 to
5194c33
Compare
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Brian Helba <brian.helba@kitware.com>
550dd78 to
3ea0baa
Compare
|
@annehaley It's been a while since I've looked at the cursor pagination implementation but I'd really like to minimize changes to the paginator if at all possible. Is it possible to just order the queryset in the API view based on the query string and let the existing paginator handle it? As it stands I don't think this is working at the moment. I think mutating state on the paginator is making the server stateful, which is leading to broken behavior e.g. request 1 orders by pinned and request 2 doesn't specify an ordering, but gets the same ordering as request 1. I believe the tests are passing by accident; for instance if I put this block after your first assertion: # List endpoint w/ no ordering
r = authenticated_client.get(reverse("api:image_list"))
ordered_ids = [image.get("isic_id") for image in r.json().get("results")]
assert ordered_ids == [image_1.isic_id, image_2.isic_id]It fails, but if I put it before, then it passes. I think we actually ought to hardcode this to sorting by our pinned images ordering. If we allow users to arbitrarily order on anything then we run in to the risk of them ordering on something that isn't indexed, which would end up needing to do full table scans repeatedly. In this case, I think we might even be allowing users to introduce joins e.g. ordering by So could we figure out how to aggressively pare back these changes, verify the pinned ordering is able to benefit from an index (it may not need a new one?), and see if it can work? |
|
Ok, if we can assume that we always want to sort images pin-first then by creation timestamp, we no longer need the However, we will still need to change the original |
|
@danlamanna As per our discussion, 3634342 isolates the custom pagination logic to a class called |
This PR does the following:
pinnedboolean field to the Image modelpinnedfield on an Image. Only staff users are permitted to set the pinned state.("-pinned", "created")so that pinned Images are shown first.DynamicOrderCursorPagination, which extendsCursorPagination. Using this pagination class allows the user to specify the ordering with theorder_byquery parameter. Theimage_listandimage_searchendpoints now use this pagination class. This will allow us to prioritize pinned images in the gallery by specifying?order_by=-pinned,created.CursorPaginationclass, where only the first field in the ordering was honored during pagination.